from tkinter import Tk
from tkinter import ttk
from database.table import tablee
from database.table.tablee import Member

def CountMember():
    count_member_screen = Tk()
    count_member_screen.title('统计员工信息')
    screen_width, screen_height = count_member_screen.maxsize()
    # 窗口的宽和高
    width = 455
    height = 200
    centre = '%dx%d+%d+%d' % (width, height, (screen_width - width) / 2,
                              (screen_height - height) / 2)
    count_member_screen.geometry(centre)
    count_member_screen.resizable(0, 0)

    memberr = tablee.session.query(Member).all()
    data = Member.to_json(memberr)
    length = len(data)

    tree = ttk.Treeview(count_member_screen)  # 创建表格对象
    tree["columns"] = ("卡号", "姓名", "电话", "积分")
    tree.column("卡号", width=50)  # 设置列
    tree.column("姓名", width=50)
    tree.column("电话", width=100)
    tree.column("积分", width=50)
    tree.heading("卡号", text="卡号")  # 显示表头名
    tree.heading("姓名", text="姓名")
    tree.heading("电话", text="电话")
    tree.heading("积分", text="积分")

    j = length - 1

    for i in range(0, length):
        num = data[j]['Mcardnum']
        name = data[j]['Mname']
        phone = data[j]['Mphone']
        point = data[j]['Mpoint']
        tree.insert("", 0, text='', value=(num, name, phone, point))
        j = j - 1
    tree.pack()

    tablee.session.close()

    count_member_screen.mainloop()

if __name__ == '__main__':
    CountMember()